JavaScript/object:修订间差异
来自康健生活
| 第70行: | 第70行: | ||
== 拷贝 == | == 拷贝 == | ||
深拷贝、浅拷贝 | 深拷贝、浅拷贝 | ||
== 等值 == | |||
{{leftrightflex|<syntaxhighlight lang="javascript"> | |||
// - 比较两个 json 对象知否相等 | |||
export const objectEqual = function objectEqual (source, target) { | |||
const sou = Object.getOwnPropertyNames(source); | |||
const tar = Object.getOwnPropertyNames(target); | |||
if (sou.length !== tar.length) return false; | |||
for (let i = 0, max = sou.length; i < max; i++) { | |||
const name = sou[i]; | |||
if (source[name] !== target[name]) return false; | |||
} | |||
return true; | |||
};</syntaxhighlight>|{{consoleout|<pre> | |||
</pre>}}}} | |||
2022年8月31日 (三) 04:44的版本
No categories