Array - push is not a function (javascript)

Asked 1 years ago, Updated 1 years ago, 87 views

var name = ['a', 'b', 'c']; 
name.push('d'); 

There was an error doing this. name.push is not a function

However, there was no problem because the variable name was changed from name to a as follows.

var a = ['a', 'b', 'c']; 
a.push('d');

Just in case Through JavaScript Variable name Validator I checked if name is a variable that should not be used, but it was okay. Why is it like this?

array push javascript

2022-09-20 10:58

1 Answers

Hello.

I tried executing the code in both cases, but there is no problem. In fact, the variable name name doesn't matter at all. You can also check that there is no problem with the browser console or running the code in the body. Maybe it's an environmental problem.


2022-09-20 10:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.