In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what are the JS skills". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what JS skills are there.
1. Ternary operator
green hand
Let hungry = true; let eat; if (hungry = = true) {eat = 'yes';} else {eat =' no';}
Veteran
Let hungry = true; let eat = hungry = = true? 'yes': 'no'
two。 Digit to string / string to digit
green hand
Let num = 15; let s = num.toString (); / / number to string let n = Number (s); / / string to number
Veteran
Let num = 15; let s = num + ""; / / digit to string let n = + s; / / string to digit
3. Fill array
green hand
For (let item0; I
< arraySize; i++){ filledArray[i] {'hello' : 'goodbye'}; } 老手 let filledArray = new Array(arraysize).fill(null).map(()=>({'hello':' goodbye'}))
4. Dynamic properties of an object
green hand
Let dynamic = "value"; let user = {id: 1,}; user [dynamic] = "other value"
Veteran
Let dynamic = "value"; let user = {id: 1, [dynamic] = "other value"}
5. Delete duplicates
green hand
Let array = [100,23,23,23,23,67,45]; let outputArray = []; let flag = false; for (j = 0)
< array.length; j++) { for (k = 0; k < outputArray.length; k++) { if (array[j] == outputArray[k]) { flag = true; } } if (flag == false) { outputArray.push(array[j]); } flag = false; } // tArray = [100, 23, 67, 45] 老手 let array = [100, 23, 23, 23, 23, 67, 45]; let outputArray = Array.from(new Set(array)) 6. 数组到对象 新手 et arr = ["value1", "value2", "value3"]; let arrObject = {}; for (let i = 0; i < arr.length; ++i) { if (arr[i] !== undefined) { arrObject[i] = arr[i]; } } 老手 let arr = ["value1", "value2", "value3"]; let arrObject = {...arr}; 7.对象到数组 新手 let number = { one: 1, two: 2, }; let keys = []; for (let numbers in numbers) { if (number.hasOwnProperty(number)) { keys.push(number); } } // key = [ 'one', 'two' ] 老手 let number = { one: 1, two: 2, }; let key = Object.keys(numbers); // key = [ 'one', 'two' ] let value = Object.values(numbers); // value = [ 1, 2 ] let entry = Object.entries(numbers); // entry = [['one' : 1], ['two' : 2]] 8. 短路条件 新手 if (docs) { goToDocs(); } 老手 docs && goToDocs() 9. 使用^检查数字是否相等 if(a!=123) // before // 一般开发者 if(a^123) // after // B格比较高的 10.对象遍历 const age = { Rahul: 20, max: 16 }; // 方案1:先得 key 在便利 key const keys = Object.keys(age); keys.forEach(key =>Age [key] +); console.log (age); / / {Rahul: 21, max: 16} / / solution 2-`for.in` cyclic for (let key in age) {age [key] +;} console.log (age); / / {Rahul: 22, max: 18}
11. Get all the keys of the object
Cosnt obj = {name: "Front-end Intelligence", age: 16, address: "Xiamen", profession: "Front-end Development",}; console.log (Object.keys (obj)); / / name, age, address, profession
twelve。 Check whether the value is an array
Const arr = [1,2,3]; console.log (typeof arr); / / object console.log (Array.isArray (arr)); / / true
13. Initialize an array of size n and fill in the default values
Const size = 5; const defaultValue = 0; const arr = Array (size) .fill (defaultValue); console.log (arr); / / [0,0,0,0,0]
14. True value and imaginary value
Imaginary values: false,0, "", null,undefined and NaN.
Truth: "Values", 0 ", {}, [].
15. The difference between third-class sign and double-equal sign
/ / A pair of equal signs-converts two operands to the same type, and then compares console.log (0 = ='o'); / / true / / third class sign-does not convert to the same type console.log (0 = ='0'); / / false
16. A better way to receive parameters
Function downloadData (url, resourceId, searchTest, pageNo, limit) {} downloadData (...); / / need to remember the order
A simpler way
Function downloadData ({url, resourceId, searchTest, pageNo, limit} = {}) {} downloadData ({resourceId: 2, url: "/ posts", searchText: "WebDev"})
17.null vs undefined
Null = > it is a value, but undefined is not.
Const fn = (x = 'default value') = > console.log (x); fn (undefined); / / default value fn (); / / default value fn (null); / / null
When passing null, the default value is not used, and when undefined or nothing is passed, the default value is used.
Thank you for your reading, the above is the content of "what are the JS skills". After the study of this article, I believe you have a deeper understanding of what JS skills you have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.