How to solve the “TypeError: array.splice is not a function” when ‘var array = {}’? [duplicate]

First of all, name your variables what they are. The name array you’re using, is misleading if you use it to create a object.

var myObject = {};

myObject[an_object]      = "xyz";
myObject[another_object] = "abc";

Now, you can delete the entry in the object with the delete statement:

delete myObject[an_object]; // Returns true / false if the deletion is a success / failure
console.log(myObject[an_object]) // Returns undefined

Now, that said, this will not work like you’d expect. myObject[an_object] will contain “abc”
Don’t use objects as keys. Use strings, instead.
This is because of the fact that any parameter entered in the [] will be converted to string. So actually, you’re entering myObject["[object Object]"]

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)