我将编写一个函数,通过使用另一个对象作为其参数来确定根据哪个键执行哪种排序,以某种方式对任何JSON进行排序(仅知道它是对象的数组,例如产品列表)。
// The json that I get might looks like something like this.
// I just write one item of the array, but all of them are the same.
// But the blueprint of the items in each json are different.
const dataArray = [
{
id: 100,
name: 'product_1',
price: 99.95,
color: ['#fff', '#f0f', '#00f'],
category: ['cat_1', 'cat_2'],
booleanKey: true,
foo: {
foo1: 12,
foo2: 'string value',
foo3: {
foo3_1: 'string value',
foo3_2: 732.342
},
foo4: [
{
foo4_1_1: …Run Code Online (Sandbox Code Playgroud)