Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

用一行代码,将数组中的字符串和字符串对象(new String(123))直接判定出来

Sunny-117 opened this issue · comments

commented
用一行代码,将数组中的字符串和字符串对象(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);