Replace Object properties value with and array value

Hi,

I’m trying to change all my object properties value with an array of values.

var obj = [["PENN, 1.01"], ["NICK", 2.05], ["DIM", 3.1], ["ARTER", 4.25], ["NEO", 90], ["IVE", 55], ["HEN", 20], ["TWEN", 60], ["HUN", 100]];

var arr = [5, 6, 7, 8, 9];

// Expected output:
var class = [["PENN, 9], ["NICK", 5], ["DIM", 3.1], ["ARTER", 6], ["NEO", 7], ["IVE", 55], ["HEN", 20], ["TWEN", 8], ["HUN", 100]];

Your help is greatly appreciated!
Cheers~

Can you explain what you want to do? It isn’t very clear what you want here.

Do you mean go from this:

class = { PENN: 9,  NICK: 5 }

To this:

class = [["PENN, 9], ["NICK", 5]]

Because that’s just Object.entries(class)

Thank you for your response. I’m trying to replace the value in the “obj” variable with the “arr” variable.

I’ve tried looping trough it but wasn’t getting the out I was looking for.

for (let i = 0; i < obj.length; i ++) {
  for (let j = 0; j < arr.length; j++) {
    obj[i][1] = arr[j];
  }
};

console.log(obj)

//Output:
[ [ 'PENN', 5 ],
  [ 'NICK', 5 ],
  [ 'DIM', 5 ],
  [ 'ARTER', 5 ],
  [ 'NEO', 5 ],
  [ 'IVE', 5 ],
  [ 'HEN', 5 ],
  [ 'TWEN', 5 ],
  [ 'HUN', 5 ] ]

Thanks!

But they’re different lengths and you aren’t putting them in the same order they appear. Unless there is something missing, the two things bear no relation to each other.

Hmmm… so there isn’t a way I can replace values in my object. With the values in an array?

We’ll, what’s the connection between them? At the minute, I can see no connection between the first array and the second array – the result you want is as if you’ve replaced some of the values with arbitrary ones contained in the array.