-1

Output should be [2,3,5,9] for both a and b as per me, as they both point to same address, and the data has a push of 9. Why the result is still the old data of [2,3,5]?

var a = [2,3,5];
var b = a; 
b.push[9];
console.log(a, b);
Deadpool
  • 7,811
  • 9
  • 44
  • 88
  • 1
    `It should be b.push(9);` – Axnyff Apr 04 '22 at 17:11
  • 2
    If you actually called the `push` method with parentheses, it’d work as expected. – deceze Apr 04 '22 at 17:11
  • 1
    If your next question is _“Why do `a` and `b` have the same content after only pushing to `b`?”_, please see [Modifying a copy of a JavaScript object is causing the original object to change](/q/29050004/4642212). – Sebastian Simon Apr 04 '22 at 18:05

1 Answers1

1

Wrong brackets you need to do b.push(9)

Paul
  • 500
  • 3
  • 8