1let arr = [
2 { name:"string 1", value:"this", other: "that" },
3 { name:"string 2", value:"this", other: "that" }
4];
5
6let obj = arr.find((o, i) => {
7 if (o.name === 'string 1') {
8 arr[i] = { name: 'new string', value: 'this', other: 'that' };
9 return true; // stop searching
10 }
11});
12
13console.log(arr);
1var obj = {
2 a: "A",
3 b: "B",
4 c: "C"
5}
6
7console.log(obj.a); // return string : A
8
9var name = "a";
10console.log(obj[name]);
1function search(nameKey, myArray){
2 for (var i=0; i < myArray.length; i++) {
3 if (myArray[i].name === nameKey) {
4 return myArray[i];
5 }
6 }
7}
8
9var array = [
10 { name:"string 1", value:"this", other: "that" },
11 { name:"string 2", value:"this", other: "that" }
12];
13
14var resultObject = search("string 1", array);
15