DEV Community

Cover image for Array_01 ABC
GiandoDev
GiandoDev

Posted on

1 1

Array_01 ABC

Alt Text
As in the code above, we may create an array by writing inside the square brackets []
You can add values ( Primitives, functions and Objects ) separate by " , " .
Since the arrays are objects, they have properties and methods, so for example, you may find how many items live inside your array by the property .length
Alt Text
Sometimes you need to get a value from an array, well you may accomplish this task in two ways:
Alt Text
Array is zero index based, so this means that the first item in the array is number 0 the second is number one and so on. In the code above we see this

const peach = [fruit.length -5] // minus 5 stand for our peach
Enter fullscreen mode Exit fullscreen mode

In fact fruit.length returns 6 that correspond to the numbers of items that we have in our array; [fruit.length -5] minus five because our peach is the second element in the array so index1 (like in the code above) so to get it we need to scale from our .length five numbers.
If we want to get the last item of the array we write:

const peach = [fruits.length -1] // 6 - 1 because the last item is index5
Enter fullscreen mode Exit fullscreen mode

If you want to set an item do this:
Alt Text
Now our peach has became a carot.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay