-1

I am new in nodejs, and I don't know how to push data to multidimensional array in nodejs.

So I have

var fruits = {
    a: { x: 1, y: 2 },
    b: { x: 3, y: 4 }
};

How to add

c: { x: 5, y: 6 }

?

I try but not work.. Thanks :)

Adrián Varga
  • 91
  • 1
  • 12

1 Answers1

0

That is not an array, it is an object. If you want to add c: { x: 5, y: 6 } to it just use fruits.c = { x: 5, y: 6 };

var fruits = {
    a: { x: 1, y: 2 },
    b: { x: 3, y: 4 }
};

fruits.c = { x: 5, y: 6 };

console.log(fruits);

More on the topic: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

Hope it helped you :)

Community
  • 1
  • 1
reymon359
  • 1,240
  • 2
  • 11
  • 34
  • yeah, sorry :D Thank you very much! :) – Adrián Varga May 10 '20 at 10:59
  • It's ok, I am glad it helped you! By the way, if you need more help with JavaScript [this free course on JavaScript Algorithms and Data Structures](https://www.freecodecamp.org/learn#javascript-algorithms-and-data-structures) could help you understand JS in a step by step way. – reymon359 May 10 '20 at 11:49