how to get the key of object in array code example

Example 1: get all keys of object in javascript

myObject = {
	"key": "value",
    "key2":"value2"
}
Object.keys(myObject);
//console.log(Object.keys(myObject))   = ["key", "key2"]

Example 2: es6 array to object keys

const subLocationTypes = (location.subLocationTypes || []).reduce((add, cur) => {
add[cur.key] = cur.value;
return add;
}, {});

Example 3: retrieve object array value based on key

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);