Skip to content

Instantly share code, notes, and snippets.

@spolat
Last active September 3, 2018 12:28
Show Gist options
  • Save spolat/b86016c0a086adc0d5fe374e61d7b6b2 to your computer and use it in GitHub Desktop.
Save spolat/b86016c0a086adc0d5fe374e61d7b6b2 to your computer and use it in GitHub Desktop.
let my_object = [
{
value: "",
class: "A"
},
{
value: "",
class: "B"
},
{
value: "",
class: "C"
}
];
let myArray = ["value1", "value2", "value3"];
my_object.map((item, index) => {
item.value = myArray[index]; // assign item.value by current index
});
console.log(JSON.stringify(my_object));
//[{"value":"value1","class":"A"},{"value":"value2","class":"B"},{"value":"value3","class":"C"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment