An Interest In:
Web News this Week
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
- March 14, 2024
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 thiscard[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 arraycard.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 arraycard.pop(newCard)
This removes the 'newCard' element from the array.
Original Link: https://dev.to/nkemdev/day-4-of-100-days-of-code-oan
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To