作业内容:自选不少于5个字符串和数组的api实例演示,特别是数组遍历方法
//字符串
str = '佐罗,好好学习天天向上'
console.log(...str)
for(i=0;i<str.length-1;i++){
console.log(str[i])
}
//类数组
str2={
0:'e',
1:'好',
2:'好',
3:'学',
4:'习',
length:5
}
//整体转成数组遍历
console.log(Array.of(str))
console.log(Array.of(...str))
//子集转为数组遍历
console.log(Array.from(str))
console.log(Array.from(str2))
console.log(Array.of(str2))
console.log(str2)
// 遍历数组
// 1.forEach
// 2.map(有返回值)
arr2=[1,2,3,4,5,6,7,8,9,0]
console.log(...arr2)
res1 = arr2.forEach(element => console.log(element));
//console.log(res1)
res2 = arr2.map(element => console.log(element));
res2 = arr2.map(element => [element]);