what is array in javascript

what is array in javascript

Javascript objects and arrays are both incredibly useful. They’re also incredibly easy to confuse with each other. Mix in a few objects that look like arrays and you’ve got a recipe for confusion!

what is array in javascript: Array in javascript are a type of object used for storing multiple values in a single variable. Each value gets numeric index and may be any data type.

We’re going to see what the differences between objects and arrays are, how to work with some of the common array-like objects, and how to get the most performance out of each.

What Objects Are

A javascript object is a basic data structure:

var basicObj = {}; // an empty object – {} is a shortcut for “new Object()”

basicObj.suprise= “cake!”;

basicObj[‘suprise’]; // returns “cake!”

Using {} instead of new Object(); is know as “Object Literal” syntax.

var fancyObj = {
favoriteFood: “pizza”,
add: function(a, b){
return a + b;

fancyObj.add(2,3); // returns 5

fancyObj[‘add’](2,3); // ditto.

As you can see, and probably already knew, properties can be accessed a couple of different ways. However, it’s an important point that we’ll come back to in a minute.

Everything in javascript is an object. Everything. Arrays, functions, even numbers! Because of this, you can do some really interesting things, such as modifying the prototypes of Objects, Arrays, etc.

What Arrays Are

Javascript arrays are a type of object used for storing multiple values in a single variable. Each value gets numeric index and may be any data type.

var arr = []; // this is a shortcut for new Array();
arr[0] = “cat”;
arr[1] = “mouse”;


See how that syntax is so similar to the syntax used for setting object properties? In fact, the only difference is that objects use a string while arrays use a number. This is why arrays get confused with objects so often.


Arrays have a length property that tells how many items are in the array and is automatically updated when you add or remove items to the array.

var arr = [];
arr[0] = “cat”; // this adds to the array
arr[1] = “mouse”; // this adds to the array
arr.length; // returns 2

arr[“favoriteFood”] = “pizza”; // this DOES NOT add to the array. Setting a string parameter adds to the underlying object
arr.length; // returns 2, not 3

The length property is only modified when you add an item to the array, not the underlying object

140 thoughts on “what is array in javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. What i do not understood is in fact how you are now
    not actually a lot more neatly-appreciated than you might be now.
    You are very intelligent. You understand therefore considerably when it comes to
    this topic, produced me individually believe it from so many various angles.

    Its like women and men don’t seem to be interested until it’s one thing to accomplish with Lady gaga!
    Your personal stuffs excellent. All the time maintain it up!

  2. I believe this is one of the most vital information for me.
    And i am satisfied studying your article. However should commentary on some common things, The website
    taste is perfect, the articles is in point of fact nice : D.
    Good job, cheers

  3. I’m not sure why but this web site is loading extremely slow for me.
    Is anyone else having this issue or is it a problem on my
    end? I’ll check back later on and see if the problem still exists.

  4. Pretty section of content. I just stumbled upon your website and in accession capital to say that I get in fact enjoyed account your weblog posts.
    Anyway I will be subscribing to your feeds or even I achievement you get right of entry to persistently quickly.

  5. Heya i’m for the primary time here. I came across this board and I to find It
    truly helpful & it helped me out a lot. I hope to give something back and help others such as you aided me.

  6. wonderful points altogether, you simply gained a new
    reader. What would you suggest in regards to your submit that you
    made a few days in the past? Any positive?

  7. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.

    You clearly know what youre talking about, why throw away your intelligence on just posting videos
    to your site when you could be giving us something informative to read?

  8. Hi there! Do you know if they make any plugins to assist with
    SEO? I’m trying to get my blog to rank for some targeted
    keywords but I’m not seeing very good results. If you know of any please share.
    Many thanks!

  9. I like the valuable information you provide in your articles.
    I’ll bookmark your blog and check again here frequently.

    I’m quite sure I’ll learn plenty of new stuff right here!
    Best of luck for the next!

  10. Hey! This is my 1st comment here so I just wanted to
    give a quick shout out and tell you I genuinely enjoy reading your posts.
    Can you recommend any other blogs/websites/forums that
    go over the same subjects? Thanks for your time!

  11. With havin so much content and articles do you ever run into
    any problems of plagorism or copyright infringement?
    My website has a lot of unique content I’ve either created myself or outsourced
    but it seems a lot of it is popping it up all over the internet without my authorization. Do you know any ways to help reduce content from being stolen? I’d definitely
    appreciate it.

  12. Howdy this is kinda of off topic but I was wondering if blogs use WYSIWYG editors
    or if you have to manually code with HTML. I’m starting a blog soon but have no
    coding knowledge so I wanted to get guidance from someone with experience.
    Any help would be greatly appreciated!

  13. Wow that was unusual. I just wrote an really long comment but after I clicked submit my comment didn’t show up.
    Grrrr… well I’m not writing all that over again. Anyway, just wanted to say great blog!

  14. Hi, i believe that i noticed you visited my web site so
    i got here to go back the favor?.I am attempting to find things to enhance my web
    site!I guess its good enough to make use of a few of your ideas!!

  15. Hey I know this is off topic but I was wondering if
    you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time
    and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to
    your new updates.

  16. You really make it seem so easy with your presentation but I find this matter to be actually something which I think I would never understand.
    It seems too complex and very broad for me.
    I am looking forward for your next post, I’ll
    try to get the hang of it!

  17. Unquestionably believe that which you stated. Your favorite reason seemed to
    be on the net the simplest thing to be aware of.

    I say to you, I definitely get annoyed while people think
    about worries that they plainly don’t know about.
    You managed to hit the nail upon the top and also defined out the whole thing without having side effect , people could take a signal.
    Will likely be back to get more. Thanks

  18. whoah this blog is great i like reading your posts.
    Keep up the great work! You recognize, a lot of people are searching round for this information,
    you can help them greatly.

  19. Aw, this was a very nice post. Finding the time
    and actual effort to generate a great article… but what can I say… I hesitate
    a whole lot and never seem to get nearly anything done.

  20. Hi, Neat post. There is an issue together with your web
    site in internet explorer, might check this? IE nonetheless is the market leader and a big section of other folks will leave
    out your excellent writing because of this problem.

  21. Hello, Neat post. There’s a problem along with your website in web explorer, might test this… IE nonetheless is the marketplace leader and a large section of other folks will miss your magnificent writing due to this problem.

  22. “Hey! This is kind of off topic but I need some advice from an established blog. Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick. I’m thinking about making my own but I’m not sure where to begin. Do you have any ideas or suggestions? With thanks”

  23. Многие люди не знают, где заказать качественные сигареты. В это время невероятно много фальшивок на распространённые фирмы. Если вы хотите приобрести табачные изделия, вам необходимо быть внимательным. Лучше заказывать табачные изделия оптом у проверенных поставщиков. Сделать это реально без особых проблем купить сигареты тут.

    На vk.com/tabakvostoka находятся разные варианты. Вы вероятно можете найти табак из ОАЭ, который известен последние месяцы. Если вам нужны табачные изделия и табак из ОАЭ, то оптимальнее заказать его у известных поставщиков. В организации продаются разные сигареты от известных фирм. Если вы желаете купить элитные табачные изделия, то сделать это не трудно.

    Если вас привлекают трубки, то вы можете поинтересоваться у менеджеров касаемо наличия трубок. Заказать табачные изделия оптом намного дешевле, чем в розницу. Сегодня интернет-магазин табачных изделий безумно пользуется спросом.

    Если вы стремитесь проконсультироваться, вы вероятно сможете сделать это через менеджеров группы. Они проконсультируют вас о всех товарах и при желании помогут с выбором.

  24. Сейчас люди не представляют, где заказать качественные сигареты. В это время невероятно много контрафакций на распространённые бренды. Если вы хотите приобрести табачные изделия, вам надо быть внимательным. Лучше приобретать сигареты оптом у надёжных поставщиков. Сделать это возможно без особых трудностей интернет-магазин сигарет тут.

    На vk.com/tabakvostoka есть интересные варианты. Вы имеете возможность найти табак из ОАЭ, который пользуется спросом последние недели. Если вам нужны сигареты и табак из ОАЭ, то оптимальнее заказать его у известных поставщиков. В фирме доступны в продаже различные сигареты от популярных компаний. Если вы желаете приобрести элитные сигареты, то сделать это просто.

    Если вас заинтересовали трубки, то вы имеете возможность поинтересоваться у менеджеров насчет каталога трубок. Заказать сигареты оптом намного дешевле, чем в розницу. Сегодня интернет-магазин сигарет безумно популярен.

    Если вы стремитесь проконсультироваться, вы имеете шанс сделать это через менеджеров сообщества. Они проинформируют вас о всех сигаретах и при необходимости посодействуют с заказом.

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.