JavaScript中数组的合并以及排序实现示例

网络编程 发布日期:2024/10/5 浏览次数:1

正在浏览:JavaScript中数组的合并以及排序实现示例

合并两个数组 - concat()
源代码:

<!DOCTYPE html>
<html>
<body>
"demo">点击按钮合并数组。</p>
"myFunction()">点我</button>
"Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var children = hege.concat(stale);
var x=document.getElementById("demo");
x.innerHTML=children;
}
</script>
"htmlcode">
Cecilie,Lone,Emil,Tobias,Linus


合并三个数组 - concat()
源代码:

<!DOCTYPE html>
<html>
<body>

<script>

var parents = ["Jani", "Tove"];
var brothers = ["Stale", "Kai Jim", "Borge"];
var children = ["Cecilie", "Lone"];
var family = parents.concat(brothers, children);
document.write(family);

</script>

</body>
</html>

测试结果:

Jani,Tove,Stale,Kai Jim,Borge,Cecilie,Lone


数组排序(按字母顺序升序)- sort()
源代码:

<!DOCTYPE html>
<html>
<body>
"demo">Click the button to sort the array.</p>
"myFunction()">Try it</button>
"Banana", "Orange", "Apple", "Mango"];
fruits.sort();
var x=document.getElementById("demo");
x.innerHTML=fruits;
}
</script>
"htmlcode">
Apple,Banana,Mango,Orange

数字排序(按数字顺序升序)- sort()
源代码:

<!DOCTYPE html>
<html>
<body>
"demo">Click the button to sort the array.</p>
"myFunction()">Try it</button>
"demo");
x.innerHTML=points;
}
</script>
"htmlcode">
1,5,10,25,40,100

数字排序(按数字顺序降序)- sort()
源代码:

<!DOCTYPE html>
<html>
<body>
"demo">Click the button to sort the array.</p>
"myFunction()">Try it</button>
"demo");
x.innerHTML=points;
}
</script>
"htmlcode">
100,40,25,10,5,1

将一个数组中的元素的顺序反转排序 - reverse()
源代码:

<!DOCTYPE html>
<html>
<body>
"demo">Click the button to reverse the order of the elements in the array.</p>
"myFunction()">Try it</button>
"Banana", "Orange", "Apple", "Mango"];
"demo");
x.innerHTML=fruits;
}
</script>
"htmlcode">
Mango,Apple,Orange,Banana

几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。