2015年10月9日
javascript
javascript中的[ ] { }是什么意思
//用{}定义一组对像
var obj = {a:1111,b:2222,c:'abc',d:function(){
alert('对像:d函数');
}};
alert('对像:'+obj.b);//调用对像b
obj.d(); //调用对像d函数
//[]是数组形式,{}是对象形式,都可以包含其他类型.
var a= ["A","B",{a:1,b:2}];
//a[1] 取得的是B,a[2].b取得的是2;
var s = {a:1,b:["A","B"]}
//s.a取得的是1,s.b[1]取得的是A
//
//
////JSON中同时使用[]和{}
var json = [{"arr1":{"a":123,"b":456},"arr2":{"a":789,"c":"abcdefg"}},{"arr1":{"a":"uuuuu","b":"oooo"},"arr2":{"a":"aaa9999","c":"abcdefg"}}];
alert('JSON1:'+json[0].arr2.a);
alert('JSON2:'+json[1].arr2.a);
split()
split() 方法用于把一个字符串分割成字符串数组。 语法:stringObject.split(separator,howmany)
。
join()
join() 方法用于把数组中的所有元素放入一个字符串。 语法:arrayObject.join(separator)
。
indexOf()
indexOf()方法可返回某个指定的字符串值在字符串中首次出现的位置。.
substring()
substring() 方法用于提取字符串中介于两个指定下标之间的字符。substring() 不接受负的参数。
decodeURIComponent()与encodeURIComponent()
encodeURIComponent()
函数可把字符串作为 URI 组件进行编码。 decodeURIComponent()
函数可对encodeURIComponent()
函数编码的 URI 进行解码。
var test1="http://www.w3school.com.cn/My first/"
document.write(encodeURIComponent(test1)+ "<br />")
document.write(decodeURIComponent(test1))
输出
http%3A%2F%2Fwww.w3school.com.cn%2FMy%20first%2F
http://www.w3school.com.cn/My first/
Last updated
Was this helpful?