1、字符串轉數組
str.split(';'); //以分號拆分字符串
2、數組轉字符串
arr.join(';'); //把數組項拼接成字符串,並以分號隔開。默認情況下是以逗號隔開
3、對象轉換為數組的方法
let arrayLike = {
'0': 'a',
'1': 'b',
'2': 'c',
length: 3
};
// ES5 的寫法
var arr1 = [].slice.call(arrayLike); // ['a', 'b', 'c']
// ES6 的寫法
let arr2 = Array.from(arrayLike); // ['a', 'b', 'c']
// NodeList 對象
let ps = document.querySelectorAll('p');
Array.from(ps).forEach(function (p) {
console.log(p);
});
// arguments 對象
function foo() {
var args = Array.from(arguments);
// ...
}
Array.from('hello')
// ['h', 'e', 'l', 'l', 'o']
let namesSet = new Set(['a', 'b'])
Array.from(namesSet) // ['a', 'b']
Array.from({ length: 3 });
// [ undefined, undefined, undefined ]
3、刪除字符串最后一個字符
var fileid=fileid.substr(0,fileid.length-1);