Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 21, 2022 10:09 pm GMT

Day 4 of 100 Days of Code

Today I learnt about calling a function within a function and arrays. An array is like a container that can hold more than one value at the same time. It could be an ordered list of items, composite data types or complex data types. This differentiates it from a variable that can just hold a value at a time.

For example

let card = [firstNumber ,secondNumber]console.log(card)

The output will be
[firstNumber,secondNumber]

To access an array, you do this
card[0].

Accessing an array starts at zero not one.
Arrays have their own built in methods. Methods can be described as functions on an object. The commonly known ones are;
Length
Concat
Push
Pop

Length
This is used to determine the number of elements in an array
card.length // This will return two as there are two elements in the card array.

Concat is used to combine two arrays and return a combined array.

cars =[ferrari, Lamboghini]card.concat(cars)

This will return [firstNumber, secondNumber,ferrari,Lamboghini]

Push
This is to add an element to the array

newCard =ThirdNumber card.push(newCard) 

This will add the new element thirdNumber into the array.

Pop
This is to remove an element from the array
card.pop(newCard)
This removes the 'newCard' element from the array.


Original Link: https://dev.to/nkemdev/day-4-of-100-days-of-code-oan

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To