MCPcopy Index your code
hub / github.com/react/react / copyWithDelete

Function copyWithDelete

packages/react-devtools-shared/src/backend/utils/index.js:55–73  ·  view source on GitHub ↗
(
  obj: Object | Array<any>,
  path: Array<string | number>,
  index: number = 0,
)

Source from the content-addressed store, hash-verified

53}
54
55export function copyWithDelete(
56 obj: Object | Array<any>,
57 path: Array<string | number>,
58 index: number = 0,
59): Object | Array<any> {
60 const key = path[index];
61 const updated = isArray(obj) ? obj.slice() : {...obj};
62 if (index + 1 === path.length) {
63 if (isArray(updated)) {
64 updated.splice(((key: any): number), 1);
65 } else {
66 delete updated[key];
67 }
68 } else {
69 // $FlowFixMe[incompatible-use] number or string is fine here
70 updated[key] = copyWithDelete(obj[key], path, index + 1);
71 }
72 return updated;
73}
74
75// This function expects paths to be the same except for the final value.
76// e.g. ['path', 'to', 'foo'] and ['path', 'to', 'bar']

Callers 2

deletePathFunction · 0.90
deletePathFunction · 0.90

Calls 1

isArrayFunction · 0.85

Tested by

no test coverage detected