原数组:
["100", "100", "2.3", "2.4", "101", "101", "3.6", "3.7"]
["100", "100", "2.3", "2.4", "101", "101", "3.6", "3.7",...."102","102".......每隔2个小数点就会有重复的,以此类推]
怎么改装成如下:
[ { type : "100", a : "2.3", b : "2.4" }, { type : "101", a : "3.6", b : "3.7" } ]
100跟101 都重复了.
How to remove duplicate numbers from an array and form a new array in js? -PHP Chinese website Q&A-How to remove duplicate numbers in an array and form a new array in js? -PHP Chinese website Q&A
Let’s take a look and learn.
给个比较简短的示例代码,注解里有写步骤123是什么:
以下给个直觉用for语句的示例,自订弹性会比较高,JS中调用函数自然是花费高,所以for语句的效能会比较好,能好到多少就要视情况测试,当然代码量会多些。步骤与上面类似:
实际上用for语句,步骤2与3可以合在一起: