What’s the difference between “{}” and “[]” while declaring a JavaScript array? Normally I declare like
var a=[];
What is the meaning of declaring the array as var a={}
What’s the difference between “{}” and “[]” while declaring a JavaScript array? Normally I declare like
var a=[];
What is the meaning of declaring the array as var a={}
When you declare
you are declaring a empty array.
But when you are declaring
you are declaring a Object .
Although Array is also Object in Javascript but it is numeric key paired values. Which have all the functionality of object but Added some few method of Array like Push,Splice,Length and so on.
So if you want Some values where you need to use numeric keys use Array. else use object. you can Create object like:
And can access values like