Skip to content

Commit 7ec6649

Browse files
authored
change object value which is inside an array
1 parent 1448ea5 commit 7ec6649

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
|35 | [Get input value as a number](#Get-input-value-as-a-number)|
4242
|36 | [reduceRight](#reduceRight)|
4343
|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+
4448

4549

4650

@@ -807,4 +811,38 @@ document.querySelector('#abort').addEventListener('click', function() {
807811
```
808812
809813
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+
810848

0 commit comments

Comments
 (0)