JS基础知识(数组)
1,数组
var colors = new Array();
var colors = new Array(20);
var colors = new Array(“red”, “blue”, “green”);
var colors = new Array(3); //create an array with three items
var names = new Array(“Greg”); //create an array with one item, the string “Greg”
var a = [1,2,3,4,5];
var b = a.shift(); //a:[2,3,4,5] b:1
var a = [1,2,3,4,5];
var b = a.unshift(-2,-1); //a:[-2,-1,1,2,3,4,5] b:7
var a = [1,2,3,4,5];
var b = a.pop(); //a:[1,2,3,4] b:5//不用返回的话直接调用就可以了
var a = [1,2,3,4,5];
var b = a.push(6,7); //a:[1,2,3,4,5,6,7] b:7
var a = [1,2,3,4,5];
var b = a.concat(6,7); //a:[1,2,3,4,5] b:[1,2,3,4,5,6,7]
放值:
var colors = [“red”, “blue”, “green”]; //define an array of strings
alert(colors[0]); //display the first item
colors[2] = “black”; //change the third item
colors[3] = “brown”; //add a fourth item
var colors = [“red”, “blue”, “green”]; //creates an array with three strings
colors[colors.length] = “black”; //add a color (position 3)
colors[colors.length] = “brown”; //add another color (position 4)
注意:
数组最多能放4,294,967,295个元素
var colors = new Array(); //create an array
var count = colors.push(“red”, “green”); //push two items
alert(count); //
count = colors.push(“black”); //push another item on
alert(count); //
var item = colors.pop(); //get the last item
alert(item); //”black”
alert(colors.length); //
JS基础知识(数组)的更多相关文章
- JS基础知识笔记
2020-04-15 JS基础知识笔记 // new Boolean()传入的值与if判断一样 var test=new Boolean(); console.log(test); // false ...
- [JS复习] JS 基础知识
项目结尾,空闲时间,又把<JS 基础知识> 这本书过了一遍,温故知新后,很多知其然不知其所以然的内容 豁然开朗. [1. 用于范围的标签] display :inline or bloc ...
- HTML+CSS+JS基础知识
HTML+CSS+JS基础知识 目录 对HTML+CSS+JS的理解 基础知识 对HTML+CSS+JS的理解 基础知识 插入样式表的三种方式 外部样式表:<link rel="sty ...
- Node.js基础知识
Node.js入门 Node.js Node.js是一套用来编写高性能网络服务器的JavaScript工具包,一系列的变化由此开始.比较独特的是,Node.js会假设在POSIX环境下运行 ...
- 网站开发进阶(十五)JS基础知识充电站
JS基础知识充电站 1.javascript alert弹出对话框时确定和取消两个按钮返回值? 用的不是alert对话框,是confirm confirm(str); 参数str:你要说的话或问题: ...
- NodeJs>------->>第三章:Node.js基础知识
第三章:Node.js基础知识 一:Node.js中的控制台 1:console.log.console.info 方法 console.log(" node app1.js 1> ...
- C语言基础知识-数组和字符串
C语言基础知识-数组和字符串 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.数组概述 在程序设计中,为了方便处理数据把具有相同类型的若干变量按有序形式组织起来的方式我们称为数组 ...
- js基础知识--BOM
之前说过,在js的 运行环境为浏览器时,js就主要有三部分组成: ECMAScript核心语法.BOM.DOM.今天就和大家详细说一下BOM的一些基础知识. BOM BOM通常被称为浏览器对象模型,主 ...
- JS基础知识总结
js基础知识点总结 如何在一个网站或者一个页面,去书写你的js代码:1.js的分层(功能):jquery(tool) 组件(ui) 应用(app),mvc(backboneJs)2.js的规划() ...
- js基础知识总结(2016.11.1)
js基础知识点总结 如何在一个网站或者一个页面,去书写你的js代码:1.js的分层(功能):jquery(tool) 组件(ui) 应用(app),mvc(backboneJs)2.js的规划():避 ...
随机推荐
- bios启动过程图解
- php定时执行PHP脚本一些方法总结
本文章总结了php定时执行PHP脚本一些方法总结,有,linux中,windows,php本身的方法,有需要的朋友可参考参考. linux下定时执行php脚本 执行PHP脚本 方法1如果你想定时执行某 ...
- mysql 在insert 时防止出现主键冲突错误的方法
在mysql中插入数据的时候常常因为主键存在而冲突报错,下面有两个解决方法: 1.在insert 语句中添加ignore 关键字,如:insert ignore into table (id,name ...
- EF的Model First
一,添加ADO.NET实体数据模型(即edmx) 1,添加edmx 新建一个类库项目,项目中添加新项,选择数据/ADO.NET实体数据模型,如下图. 点击添加,实体数据模型向导窗口 ...
- uva 1210
#include<iostream> #include<cstring> using namespace std; + ; bool notprime[MAXN];//值为fa ...
- [JS]getYear()和getFullYear()方法区别
getFullYear();总是返回4位完整的年份 getYear();当年份在1900-1999时,返回两位数字,如1980返回80,当不在这个范围时,返回同getFullYear(); 注:get ...
- SGU 140 扩展欧几里得
题目大意: 给定序列a[] , p , b 希望找到一个序列 x[] , 使a1*x1 + a2*x2 + ... + an*xn = b (mod p) 这里很容易写成 a1*x1 + a2*x2 ...
- 戴文的Linux内核专题:08内核配置(4)
转自Linux中国 这个第四部分里,我们将继续配置更多的设置和特性. 这里我们被问及关于"IBM Calgary IOMMU support (CALGARY_IOMMU)".这个 ...
- iOS开发之UITableView使用总结
什么是UITableView 在众多移动应用中,能看到各式各样的表格数据 在iOS中,要实现表格数据展示,最常用的做法就是使用UITableView UITableView继承自UIScrollVie ...
- python视频教程:十分钟快速入门python
想要学习python这门语言,却始终找不到一个全面的Python视频教程,倘若你是真心想学好一门语言,小编建议你亲自动手实践的.下面来看看入门python的学习教程. Python的语言特性 Pyth ...