We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 725fe5f commit e696b80Copy full SHA for e696b80
id-prep.ts
@@ -0,0 +1,24 @@
1
+
2
+class IdGenerator {
3
+ private static id: number = 0;
4
+ public static getNextId() {
5
+ return ++IdGenerator.id;
6
+ }
7
+}
8
9
+export function extendArrayElementsByUniqueId(arr: any[]): any[] {
10
+ if (!arr || arr.length == 0) return [];
11
+ const firstElement = arr[0];
12
13
+ if (typeof firstElement === 'object') {
14
+ arr.forEach((element: any) => {
15
+ if (!element.id) {
16
+ element.id = IdGenerator.getNextId();
17
18
+ });
19
+ return arr;
20
+ } else {
21
+ return arr.map((element: any) => { return { value: element, id: IdGenerator.getNextId() } });
22
23
24
0 commit comments