数组的fill方法

JavaScript fill()方法 (JavaScript fill() method)

fill() method is used fill the array with a given value.

fill()方法用于使用给定值填充数组。

Syntax:

句法:

    array.fill(value, [start_index], [end_index]);

Parameters:

参数:

  • value is a static value to be filled in the array.

    value是要填充到数组中的静态值。

  • start_index is an optional parameter, it specifies the starting index to fill the array, its default value is 0.

    start_index是一个可选参数,它指定填充数组的起始索引,其默认值为0。

  • end_index is also an optional parameter, it specifies the ending index to fill the array, its default value is array.length.

    end_index也是一个可选参数,它指定填充数组的结束索引,其默认值为array.length 。

Return value: None

返回值:

Example:

例:

    Input:
var arr = [10, 20, 30, 40, 50];
Function call:
arr.fill(0);
Output:
0,0,0,0,0

JavaScript Code to demonstrate example of Array.fill() method

JavaScript代码演示Array.fill()方法的示例

<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var arr = [10, 20, 30, 40, 50];
document.write("array elements: " + arr + "<br>");
//filling all elements
arr.fill(0);
document.write("array elements: " + arr + "<br>");
//filling initial 2 elements with 100
arr.fill(10, 0, 2);
document.write("array elements: " + arr + "<br>");
//filling next 3 elements with 200
arr.fill(200, 2, 5);
document.write("array elements: " + arr + "<br>");
</script>
</body>
</html>

Output

输出量

array elements: 10,20,30,40,50
array elements: 0,0,0,0,0
array elements: 10,10,0,0,0
array elements: 10,10,200,200,200

翻译自: https://www.includehelp.com/code-snippets/array-fill-method-with-example-in-javascript.aspx

数组的fill方法

数组的fill方法_数组fill()方法以及JavaScript中的示例相关推荐

  1. java 数组的方法_数组常用方法

    [TOC] # 定义 ~~~ //初始化一个长度为8的定长数组,其所有元素均为0 val arr1 = new Array[Int](8) //直接打印定长数组,内容为数组的hashcode值 pri ...

  2. c++ 数组截取_【学习教程】JavaScript中原生Array数组方法详解

    来源 | http://www.fly63.com/article/detial/9692 JS中,数组可以通过阵列构造函数或[]字面量的方式创建.数组是一个特殊的对象,继承自对象原型,但用typeo ...

  3. find 命令示例_数组find()方法以及JavaScript中的示例

    find 命令示例 JavaScript find()方法 (JavaScript find() method) find() method is used to get the first elem ...

  4. 数组中的filter方法_数组filter()方法以及JavaScript中的示例

    数组中的filter方法 JavaScript filter()方法 (JavaScript filter() method) filter() method is used to returns a ...

  5. 数组tostring方法_数组toString()方法以及JavaScript中的示例

    数组tostring方法 JavaScript toString()方法 (JavaScript toString() method) toString() method is used to con ...

  6. 数组push()方法以及JavaScript中的示例

    JavaScript push()方法 (JavaScript push() method) push() method is used adds/inserts an element at the ...

  7. JAVA数组扁平化整合_数组扁平化的几种处理放法

    清明节,这几天放假闲来无事,好好研究一下基础知识,今天看看数组扁平化该怎么处理: 先来看数组扁平化是什么: var arr = [1,2,3,4,[5,6,[7,8]],true] => [1, ...

  8. main方法_错误: 在类 ZiFUChuan.Pyramid 中找不到 main 方法, 请将 main 方法定义为:

    错误: 在类 ZiFUChuan.Pyramid 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args) 否则 Java ...

  9. 如何给6个整数的一维数组某个元素赋值_数组指针详解

    文章部分资料来源: Pointer to an Array | Array Pointer - GeeksforGeeks​www.geeksforgeeks.org 介绍数组指针之前,先来回顾指针: ...

最新文章

  1. 必看,10篇定义计算机视觉未来的论文
  2. photoshop 图片转 pdf
  3. 样本不均衡常见解决方法
  4. java树 JTree实例(可动态添加节点)
  5. 关于实验中的makefile相关知识
  6. JS中怎样将时间字符串转换成Date并比较大小
  7. rabbitmq在web管理界面登录失败login fail
  8. JavaScript实现截留雨水问题的动态编程方法算法(附完整源码)
  9. git报错fatal: HTTP request failed
  10. 关于模型转向自然化思考
  11. 融资、上市,悦刻又在讲电子烟的未来
  12. Vue 作者尤雨溪,引路中国程序开发
  13. 几步操作即可实现WhatsApp群发
  14. 如何在Mac上给移动硬盘加密
  15. 鸿蒙杀戮手机电脑版,鸿蒙杀戮单职业
  16. 厚颜无耻的免费使用Visio和project2016
  17. 唠唠 U盘格式 (Normal:FAT32 NTFS exFAT)以及U盘格式化选什么格式好???
  18. 如果用一个循环数组q[0..m-1]表示队列时,该队列只有一个队列头指针front,不设队列尾指针rear,求这个队列中从队列投到队列尾的元素个数(包含队列头、队列尾)。
  19. 进制转换(任意进制转换)
  20. Hadoop_shell脚本

热门文章

  1. python读取文件最后几行_如何用python获取文件的最后一行,文件可能会比较大
  2. Latex 中插入超链接 插入网址
  3. WebP 在减少图片体积和流量上的效果如何?MIP技术实践分享
  4. Angular自动取消订阅RxJs
  5. Angular实现dialog对话框封装
  6. Node.js的基本使用3
  7. 浅析Nginx 正向代理与反向代理
  8. Thrift源码学习二——Server层
  9. AOE网与关键路径简介
  10. iOS中的UIScrollView(滑动视图)