|
41 | 41 | |35 | [Get input value as a number](#Get-input-value-as-a-number)|
|
42 | 42 | |36 | [reduceRight](#reduceRight)|
|
43 | 43 | |37 | [Abort Fetch](#Abort-Fetch)|
|
| 44 | +|38 | [How to change the value of an object which is inside an array](#How-to-change-the-value-of-an-object-which-is-inside-an-array)| |
| 45 | + |
| 46 | + |
| 47 | + |
44 | 48 |
|
45 | 49 |
|
46 | 50 |
|
@@ -807,4 +811,38 @@ document.querySelector('#abort').addEventListener('click', function() {
|
807 | 811 | ```
|
808 | 812 |
|
809 | 813 |
|
| 814 | +**[⬆ Back to Top](#table-of-contents)** |
| 815 | +### How to change the value of an object which is inside an array |
| 816 | + |
| 817 | +```javascript |
| 818 | + |
| 819 | +const state = [ |
| 820 | + { |
| 821 | + userId: 1, |
| 822 | + name: "JSSnippets", |
| 823 | + isOwner: false, |
| 824 | + }, |
| 825 | + { |
| 826 | + userId: 2, |
| 827 | + name: "React", |
| 828 | + isOwner: false, |
| 829 | + }, |
| 830 | + { |
| 831 | + userId: 3, |
| 832 | + name: "Vue", |
| 833 | + isOwner: false, |
| 834 | + }, |
| 835 | + { |
| 836 | + userId: 4, |
| 837 | + name: "Angular", |
| 838 | + isOwner: false, |
| 839 | + }, |
| 840 | +]; |
| 841 | + |
| 842 | +const newState = state.map((obj) => |
| 843 | + obj.name === "JSSnippets" ? { ...obj, isOwner: true } : obj |
| 844 | +); |
| 845 | + |
| 846 | +``` |
| 847 | + |
810 | 848 |
|
0 commit comments