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 :)
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 :)
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 :)