There is an array of the form:

var mass_elem = { "A1" : { "bend" : "198", "asp" : "155", "m2" : "32" }, "A2" : { "bend" : "100", "asp" : "155", "m2" : "32" }, "A3" : { "bend" : "55", "asp" : "155", "m2" : "32" }, } 

Like this array you can make an array of the form:

 var mass_elem_2 = { "A1": "198", "A2": "100", "A3": "55", } 

That is, you need to leave the value from the bend field, and instead of the bend key, the key of the mass_elem array. And the rest of the field to remove.

    1 answer 1

    Since the question is not arrays, but objects. First you need to get their keys, and then apply the reduce method.

     var elem = { "A1": { "bend": "198", "asp": "155", "m2": "32" }, "A2": { "bend": "100", "asp": "155", "m2": "32" }, "A3": { "bend": "55", "asp": "155", "m2": "32" }, }; var result = Object.keys(elem).reduce(function(object, cur) { object[cur] = elem[cur].bend; return object; }, {}); console.log(result); 

    • but an associative array is an object in JS, isn't it? - Sasha Omelchenko
    • @SashaOmelchenko, of course not: an object is not an array. - Grundy
    • @SashaOmelchenko in general, in js, everything is an object, specifically an array is [], meaning to exorcise terminology. - Jean-Claude
    • one
      @SashaOmelchenko, in general, this is a question of terminology. Just the majority of people using the term associative array , in relation to an object in JS, came from php, and there the behavior of arrays with non-numeric keys is very different from the behavior of objects in Js, so it is better to distinguish these terms right away. - Grundy