当前位置:网站首页>JS common interview questions
JS common interview questions
2022-07-25 03:07:00 【Gary_ Leong】
map and forEach The difference between
- map It's faster than forEach;
- map Will return a new array , It doesn't change the original array ;forEach No new array will be returned , It is allowed to modify the original array ;
- They all have parameters :item、index、arr
- Of internal anonymous functions this All points are window;
String to character array
- split() Method
const text = "abc";
const chars = text.split('');
console.log(chars);
//['a', 'b', 'c']
- Expand operator
Expand operator ( …) Allow multiple elements when needed ( Such as array text ) Where to extend iteratable objects such as strings .
This is an example of expanding a string into a character array . Correctly handle characters with two code units .
const text = "abc????";
const chars = [ ...text ];
console.log(chars);
//["a", "b", "c", "????"]
- Deconstruct assignment
Deconstruction assignment syntax can unpack the values in an array or an iteratable object into different variables .
When deconstructing arrays or iteratable objects , We can use rest The pattern extracts the rest of it into a single variable .
const text = "abc????";
const [ ...chars ] = text;
console.log(chars);
//["a", "b", "c", "????"]
- Array.from
Array.from Assists in creating new arrays of objects that are arrayed or iterated . Strings are both iteratable and similar to arrays , therefore , It can be successfully converted to a character array .
const text = "abc????";
const chars = Array.from(text);
console.log(chars);
//["a", "b", "c", "????"]
边栏推荐
- Arduino IDE for raspberry PI Pico development firmware localization installation tutorial
- JS written test question -- browser kernel
- Resolved (the latest version of selenium reported an error) attributeerror: module 'selenium webdriver‘ has no attribute ‘PhantomJS‘
- Do you know about real-time 3D rendering? Real time rendering software and application scenarios are coming
- Common Oracle commands
- Wechat sports field reservation of the finished works of the applet graduation project (7) mid-term inspection report
- The difference between abstract classes and interfaces
- Riotboard development board series notes (VII) -- the use of framebuffer
- Idea configuration
- Flink's study notes
猜你喜欢

PHP record

Use of stm32cubemonitor Part II - historical data storage and network access

Dynamic programming -- Digital DP

Pypi counts the number of Downloads

MySQL common function summary, very practical, often encountered in interviews

Learning record 10

FLASH read / write problem of stm32cubemx

Flume's study notes

mysql_ Record the executed SQL

Resolved (the latest version of selenium reported an error) attributeerror: module 'selenium webdriver‘ has no attribute ‘PhantomJS‘
随机推荐
Backtracking to solve subset problem
How to switch terminators in PostgreSQL?
Banana pie bpi-m5 toss record (3) -- compile BSP
[Kali's sshd service is enabled]
Method of adding kernel in Jupiter notebook
List title of force buckle summary
How to take the mold for the picture of 1.54 inch TFT st7789 LCD screen
DOM node type
# CF #807 Div.2(A - D)
Web -- JDBC tool class writing
Wechat sports field reservation of the finished works of the applet graduation project (7) mid-term inspection report
NVM installation and use
Use of stm32cubemonitor Part II - historical data storage and network access
Physical experiment simulation
[jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality
JS written test question -- deep copy of object
JS written test questions -- random numbers, array de duplication
JS construction linked list
Learning record XIII
Learning record 10