Search This Blog

2023/09/11

Typescript: Array.from

var str1 = Array.from("sangram")
console.log(str1)

var set = new Set()
set.add("sagar").add("sangram").add("sachin")
console.log(set)


var myarr1 = Array.from(set)
console.log(myarr1)

var double = Array.from([1, 2, 3], (x) => x + x)
console.log(double)

var indexArray = Array.from({ length: 5 }, (_current, index) => {
return index
})
//_current here underscore say we dont need this variable in function
console.log(indexArray)


Output:
[ 's', 'a', 'n', 'g', 'r', 'a', 'm' ] Set(3) { 'sagar', 'sangram', 'sachin' } [ 'sagar', 'sangram', 'sachin' ] [ 2, 4, 6 ] [ 0, 1, 2, 3, 4 ]

No comments:

Post a Comment