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

js如何翻转一个字符串&&js如何清除数组 #13

Open
xiaohesong opened this issue Dec 1, 2018 · 0 comments
Open

js如何翻转一个字符串&&js如何清除数组 #13

xiaohesong opened this issue Dec 1, 2018 · 0 comments
Labels
tips 一些不错的想法

Comments

@xiaohesong
Copy link
Owner

翻转字符串

How to reverse a string in JavaScript

const str = "hello"
str.split('').reverse().join('')
//"olleh"
const str = "hello"
[...str].reduce((prev,next)=>next+prev)
//"olleh"
function reverseString(str){
  const arr = [...str]
  let reverse= "";
  while(arr.length){
     reverse = reverse + arr.pop()
  }
  return reverse
}

清空数组

How to clear an array in javascript

var arr = [1,2,3,4,5,6] 
arr = [ ]
console.log(arr)
//empty array [ ] 
var arr = [1,2,3,4,5,6]
arr.length = 0
console.log(arr)
//empty array [ ]
var arr = [1,2,3,4,5,6]
while(arr.length){
   arr.pop()
}
console.log(arr)
//empty array [ ]
@xiaohesong xiaohesong added the tips 一些不错的想法 label Dec 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tips 一些不错的想法
Projects
None yet
Development

No branches or pull requests

1 participant