用一行代码,将数组中的字符串和字符串对象(new String(123))直接判定出来
Sunny-117 opened this issue · comments
用一行代码,将数组中的字符串和字符串对象(new String(123))直接判定出来
function judeg(arr){
return arr.map(item => typeof item === "string" ? "string" : "new String()")
}
let arr = ['hello', new String('123'), 123, true, {}, [], null];
let stringItems = arr.filter(item => typeof item === 'string' || item instanceof String);