Sort an array except one element in JavaScript

前端 未结 10 2549
感动是毒
感动是毒 2021-02-12 01:31

I have an array and I am sorting it but I need to sort everything except one element of my array.

My array is:

var Comparison = [
    {key: \"None\", val         


        
10条回答
  •  盖世英雄少女心
    2021-02-12 02:10

    const array1 = this.Comparison.filter(e => e.key === 'None');
    const array2 = this.Comparison
                .filter(e => e.key !== 'None')
                .sort((a, b) => a.key.localeCompare(b.key));
    
    this.Comparison = [].concat(array1, array2);
    

提交回复
热议问题