2

Just a simple question, but can't get an answer on my own.

In memory Array are use contiguous space to store the data.

Object use pointer to look where the data are stored.

(correct me if i'm wrong :D )

In Javascript Array are object, does it means that Array work like object for memory storage ?

1 Answer 1

3

Since you can't get references to actual memory locations in Javascript, what difference does it make *how the memory is allocated? In Javascript, everything is an Object because there isn't even a type for anything (really)... var foo = 5; foo = "hello"; foo = function(){}; and so on and so forth. All you need to know is how an Array works in javascript. Don't worry about how it's storing its values and where... that's not something you have any control over and it makes absolutely no difference.

Sign up to request clarification or add additional context in comments.

4 Comments

want to know it for performance, in my mind array are faster than object
you're going to have to allow the interpreter to handle the performance, and not "your mind" :) Seriously though, it's not like you have an option. There isn't a lower level array type for you to take advantage of, so, it's going to be as fast as it's going to be... As it happens... and all things considered, it's pretty fast.
@jbduzan An array and an object have two different purposes (in the context of data storage). To oversimplify quite a bit: objects are hash maps; arrays are "arrays."
@GeniaS. Where do these objects get their memory allocation? In browser or Local storage of computer?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.