JavaScript数组的调用

1.数组的调用

描述:数组的调用实际上是指数组元素的调用。数组元素通过【数组名+下标】的方式来进行访问。

语法:数组名[下标]

	var i = ['a','b','c']
	console.log(i[1]);

2.要求定义一个5个元素的数组,并分别打印数组的每个元素,要求使用快速遍历

	var arr = ['a','b','c','d','e'];
	for (index in arr) [
		console.log(arr[index]);
	}
	//普通for循环
	for (var i = 0;i<arr.length;i++) {
		console.log(arr[i]);
	}

3.需求二:由于代码过长,直接上图片

JavaScript中关于数组的调用方式

伪数组JS调用数组方法

function show() {
  [].forEach.call(arguments, (v, i) => {
    console.log(v);
  });
}

function show() {
  [].forEach.apply(arguments, [
    (v, i) => {
      console.log(v);
    },
  ]);
}

function show() {
  [].forEach.bind(arguments)((v, i) => {
    console.log(v);
  });
}
  • call后的第二个参数传的是原方法的参数列表
  • apply后的第二个参数传的是 数组 数组里是参数,数组长度与原方法的参数个数一致
  • bind后绑定对象,后还需继续传入(原方法的参数列表) 

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文地址:https://blog.csdn.net/xiaoding520/article/details/104161152

相关文章:

  • 2021-06-19
  • 2021-10-14
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
猜你喜欢
  • 2021-10-14
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-09-16
  • 2021-11-01
  • 2021-12-08
相关资源
相似解决方案