lodash merge mergeWith使用


1、作用

遞歸合並來源對象的自身和繼承的可枚舉屬性到目標對象。 

2、示例

<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>lodash mergeWith使用</title>
    </head>

    <body>
        <script src="https://cdn.bootcss.com/lodash.js/4.17.10/lodash.min.js"></script>
        <script type="text/javascript">
            function customizer(objValue, srcValue) { if(_.isArray(objValue)) { return objValue.concat(srcValue); } } var object = { 'fruits': ['apple'], 'vegetables': ['beet'] }; var other = { 'fruits': ['banana'], 'vegetables': ['carrot'] }; let o1 = _.mergeWith(object, other, customizer); let o2 = _.mergeWith(object, other); let o3 = _.merge(object, other); console.log(_.isEqual(o1, o2)) //true
 console.log(_.isEqual(o3, o2)) //true
        </script>
    </body>

</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM