-
Notifications
You must be signed in to change notification settings - Fork 136
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
前端存档 #80
Comments
在 js中 [1] in [[1,2], [1], [1,2,3]] 无论是includes 还是indexof都不好用。 |
splice() 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。此方法会改变原数组。 //从第 2 位开始删除 0 个元素,插入“drum”
var myFish = ["angel", "clown", "mandarin", "sturgeon"];
var removed = myFish.splice(2, 0, "drum");
//从第 2 位开始删除 0 个元素,插入“drum” 和 "guitar"
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish.splice(2, 0, 'drum', 'guitar');
// 从第 3 位开始删除 1 个元素
var myFish = ['angel', 'clown', 'drum', 'sturgeon'];
var removed = myFish.splice(2, 1, "trumpet") |
js 判断是否为回文数 function palindrome(str) {
// Step 1. The first part is the same as earlier
var re = /[^A-Za-z0-9]/g; // or var re = /[\W_]/g;
str = str.toLowerCase().replace(re, '');
// Step 2. Create the FOR loop
var len = str.length; // var len = "A man, a plan, a canal. Panama".length = 30
for (var i = 0; i < len/2; i++) {
if (str[i] !== str[len - 1 - i]) { // As long as the characters from each part match, the FOR loop will go on
return false; // When the characters don't match anymore, false is returned and we exit the FOR loop
} |
slice() works like substring() with a few different behaviors. Syntax: string.slice(start, stop); If start equals stop: returns an empty string If start > stop, then substring will swap those 2 arguments. If start > stop, slice() will return the empty string. ("") |
这个东西是浅拷贝,必须用深拷贝,妈的 |
嵌套数组如何set 和判断是否在数组中
|
The text was updated successfully, but these errors were encountered: