Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

练习题7:取出数组里面的负数 #18

Open
chenhuiYj opened this issue Jul 3, 2020 · 0 comments
Open

练习题7:取出数组里面的负数 #18

chenhuiYj opened this issue Jul 3, 2020 · 0 comments

Comments

@chenhuiYj
Copy link
Owner

给出一个数组,数组里面的成员可是数值,字符串,对象,数组。找出里面所有的字符串

let arr=[-6.236,3,-21,{a:-11,b:{c:-10}},[11,2.26,[-1,-6,]]]
console.log(JSON.stringify(str).split('-').splice(1).map(item=>-Number.parseFloat(item)))

解题思路:首先把数组转成 json ,然后按照 ’-‘ 分割字符,把第一个元素删除,再用 Number.parseFloat 把字符串转成 数值

关键点:Number.parseFloat

Number.parseFloat('12asd31{{}') //12
@chenhuiYj chenhuiYj changed the title 练习题7:去除数组里面的负数 练习题7:取出数组里面的负数 Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant