entry数组_数组entry()方法以及JavaScript中的示例

entry数组

JavaScript entry()方法 (JavaScript entries() method)

entries() method is used to create an iterator object of an array to access the keys (index) and values.

entry()方法用于创建数组的迭代器对象,以访问键(索引)和值。

Syntax:

句法:

    array.entries();

Parameters: None

参数:

Return value: An iterator object of the array.

返回值:数组的迭代器对象。

Note: To print the key, value using iterator, we use iterator.next().value.

注意:要使用迭代器打印键值,我们使用iterator.next()。value 。

Example:

例:

    Input:
    var names = ["Manju", "Amit", "Abhi", "Radib", "Prem"];

    Function call:
    var it = names.entries();
    it.next().value;
    
    Output:
    0,Manju

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

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

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>
		var names = ["Manju", "Amit", "Abhi", "Radib", "Prem"];
		
		//creating an iterator 
		var it = names.entries();
		
		//printing keys(index) & values 
		document.write(it.next().value + "<br>");
		document.write(it.next().value + "<br>");
		document.write(it.next().value + "<br>");
		document.write(it.next().value + "<br>");
		document.write(it.next().value + "<br>");		
	</script>
</body>
</html>

Output

输出量

0,Manju
1,Amit
2,Abhi
3,Radib
4,Prem


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

entry数组