Array object: an array variable is an array object
length property: dynamically obtains the length of the array. For example: var len = arrObj.length
##join()
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //将以下字符串转成数组, 然后再转成字符串 var str = "北京,上海,深圳,南京,合肥"; //转成数组 var arr=str.split(","); //再转换成字符串 str = arr.join(",") ; document.write("类型是:"+typeof(str)+",字符串为:"+str); </script> </head> <body> </body> </html>
##reverse()
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var arr=[1,2,3,4,5,6,7,8]; arr.reverse(); document.write(arr); </script> </head> <body> </body> </html>
Deletion and addition of array elements
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //使用delete删除元素,查看长度是否改变 var arr=[1,2,3,4,5,6,7,8]; document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); delete arr[0]; delete arr[1]; delete arr[2]; document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); </script> </head> <body> </body> </html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //使用delete删除元素,查看长度是否改变 var arr=[1,2,3,4,5,6,7,8]; document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); arr.shift(); document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); arr.pop(); document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); </script> </head> <body> </body> </html>
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //使用delete删除元素,查看长度是否改变 var arr=[1,2,3,4,5,6,7,8]; document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); arr.unshift(0); document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); arr.push(9); document.write("数组的长度为"+arr.length+",值为"+arr+"<br/>"); </script> </head> <body> </body> </html>Next Section