Method is used for arrange your object keys from array. it will put all object keys with same key+value in duplicatedKeys itt will put all object keys with different key+values in uniqueKeys
yarn add extract-array-keys
npm install extract-array-keys
Name | Type | Default | Description |
---|---|---|---|
array | ArrayKey[] |
required |
The array you want to arrange, must be an object array, object could be nested |
excludedKeys | string[] |
[] |
The keys you want to remove(set as duplicatedKeys) by default |
includedKeys | string[] |
[] |
The keys you want to keep(set as uniqueKeys) by default |
specificKey | string |
undefined |
if object is nested, the specific key you want to start from |
Name | Type | Description |
---|---|---|
duplicatedKeys | string[] |
Could get all excludedKeys from array |
uniqueKeys | string[] |
Could get all includedKeys from array |
import extractArrayKeys from 'extract-array-keys'
// with only array
const { duplicatedKeys, uniqueKeys } = extractArrayKeys({
array: [
{ a: 1, b: 2, c: 3, d: 4 },
{ a: 1, b: 2, c: 3, d: 5 },
{ a: 1, b: 2, c: 4, d: 6 },
{ a: 1, b: 2, c: 4, d: 7 },
],
});
console.log(duplicatedKeys)
// ["a", "b"]
console.log(uniqueKeys)
// ["c", "d"]
import extractArrayKeys from 'extract-array-keys'
// with only array
const { duplicatedKeys, uniqueKeys } = extractArrayKeys({
array: [
{ a: 1, b: 2, c: 3, d: 4 },
{ a: 1, b: 2, c: 3, d: 5 },
{ a: 1, b: 2, c: 4, d: 6 },
{ a: 1, b: 2, c: 4, d: 7 },
],
excludedKeys: ["c"],
});
console.log(duplicatedKeys)
// ["a", "b", "c"]
console.log(uniqueKeys)
// ["d"]
import extractArrayKeys from 'extract-array-keys'
// with only array
const { duplicatedKeys, uniqueKeys } = extractArrayKeys({
array: [
{ a: 1, b: 2, c: 3, d: 4 },
{ a: 1, b: 2, c: 3, d: 5 },
{ a: 1, b: 2, c: 4, d: 6 },
{ a: 1, b: 2, c: 4, d: 7 },
],
includedkeys: ["a"],
});
console.log(duplicatedKeys)
// ["b"]
console.log(uniqueKeys)
// ["a", "c", "d"]
const { duplicatedKeys, uniqueKeys } = extractArrayKeys({
specificKey: "metric",
array: [
{ metric: { a: 1, b: 2, c: 3, d: 4 }, value: { x: 1, y: 2, z: 3 } },
{ metric: { a: 1, b: 2, c: 3, d: 4 }, value: { x: 1, y: 2, z: 3 } },
{ metric: { a: 1, b: 2, c: 3, d: 5 }, value: { x: 1, y: 2, z: 3 } },
{ metric: { a: 1, b: 2, c: 4, d: 6 }, value: { x: 1, y: 2, z: 3 } },
{ metric: { a: 1, b: 2, c: 4, d: 7 }, value: { x: 1, y: 2, z: 3 } },
],
excludedKeys: ["c"],
includedKeys: ["a"],
});
console.log(duplicatedKeys)
// ["b", "c"]
console.log(uniqueKeys)
// ["a", "d"]