EN
JavaScript - "TypeError: array.splice is not a function"?
1
answers
0
points
How can I fix the following error?
"TypeError: array.splice is not a function"
My code:
// ONLINE-RUNNER:browser;
var array = { 0: 'a', 1: 'b' };
array.splice(0, 1);
I want to remove a 0: 'a'
key/value pair from the array
variable.
1 answer
0
points
You named the variables wrong. What you are trying to do is use an object to create an array.
If you want to remove the object property use delete
operator.
// ONLINE-RUNNER:browser;
var object = { 0: 'a', 1: 'b' };
delete object[0];
console.log(JSON.stringify(object)); // {"1":"b"}
See also
References
0 comments
Add comment