How js removes imaginary values from an array
This article will explain in detail how js removes imaginary values from the array. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Remove an imaginary value from an array
In some cases, we want to remove imaginary values from the array. An imaginary value is a value in JavaScript whose value is FALSE. There are only six imaginary values in JavaScript. They are:
Undefined
Null
NaN
0
'' (empty character)
False
The easiest way to filter these virtual values is to use the following function:
MyArray.filter (Boolean)
If you want to make some changes to the array and then filter the new array, you can try this. Keep in mind that the original myArray remains the same.
MyArray .map (item = > {/ / Do your changes and return the new item}) .filter (Boolean); this is the end of the article on "how js removes virtual values from an array". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.