Array object in TS Usage in
*
length length
let songs:string[]=['red','blue','pink']
console.log(songs.length)
*
push**push()** Method adds one or more elements to the end of the array , And return the new length of the array
3.**forEach()** Method executes the given function once for each element of the array , Will run 5 second , And it can't stop in the middle .
let songs: string[]=['red','green','pink']
songs.forEach(function(item,index){
console.log(' Index is ',index,‘ Element is ’,item)
})
notes :forEach The parameter of the method is a function , This function is also called a callback function
1.item Represents each element in the array , amount to songs[i]
2.index Represents an index , amount to i
The callback function here is as forEach Method arguments passed in , Type annotation should not be specified ( On call forEach Yes, it has been created )
// It is understood as hiding
function forEach(callbackfn: (value:string,index:number)=>void){
}
forEach(function(value,index){})
3.some As long as one of the conditions is met , Will stop the cycle , And according to the return value , Decide whether to stop the cycle (ture, stop it ;false, continue )
let nums:number[]=[1,2,3,4,5,6]
nums.some(function (num){
if(num>3){
return true
}
return false
})
Technology