How to append object to array using in JavaScript

2 Answers

0 votes
let array = [1, 2, 3, 4];

let object = {x: 33, y: 55};

array.push(object);

console.log(array);
   
   
   
   
/*
run:
   
[1, 2, 3, 4, {
  x: 33,
  y: 55
}]
   
*/

 



answered Jan 24, 2022 by avibootz
0 votes
let array = [1, 2, 3, 4];

let object = {x: 33, y: 55};

const index = array.length;

array.splice(index, 0, object);

console.log(array);
   
   
   
   
/*
run:
   
[1, 2, 3, 4, {
  x: 33,
  y: 55
}]
   
*/

 



answered Jan 24, 2022 by avibootz

Related questions

1 answer 193 views
1 answer 165 views
2 answers 196 views
1 answer 186 views
1 answer 187 views
1 answer 177 views
...