一、把数组转换为字符串
JavaScript 方法 toString() 把数组转换为数组值(逗号分隔)的字符串。
实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数组方法</title>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.write(fruits.toString())
</script>
</head>
<body>
</body>
</html>
效果图
二、join() 方法也可将所有数组元素结合为一个字符串。
实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数组方法</title>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.write(fruits.join("*"))
</script>
</head>
<body>
</body>
</html>
效果图
三、Popping
pop() 方法从数组中删除最后一个元素
实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数组方法</title>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop()
document.write(fruits.toString())
</script>
</head>
<body>
</body>
</html>
效果图
四、Pushing
push() 方法(在数组结尾处)向数组添加一个新的元素
实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数组方法</title>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("MW")
document.write(fruits.toString())
</script>
</head>
<body>
</body>
</html>
效果图
五、删除元素
既然 JavaScript 数组属于对象,其中的元素就可以使用 JavaScript delete 运算符来删除
实践
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数组方法</title>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.write(fruits[0]+"<br/>");
delete fruits[0];
document.write(fruits[0]);
</script>
</head>
<body>
</body>
</html>