Comparing two arrays of objects, and exclude the elements who match values into new array in JS

well, this using lodash or vanilla javascript it depends on the situation. but for just return the array that contains the differences can be achieved by the following, offcourse it was taken from @1983 var result = result1.filter(function (o1) { return !result2.some(function (o2) { return o1.id === o2.id; // return the ones with equal id … Read more

One liner to flatten nested object

Here you go: Object.assign({}, …function _flatten(o) { return [].concat(…Object.keys(o).map(k => typeof o[k] === ‘object’ ? _flatten(o[k]) : ({[k]: o[k]})))}(yourObject)) Summary: recursively create an array of one-property objects, then combine them all with Object.assign. This uses ES6 features including Object.assign or the spread operator, but it should be easy enough to rewrite not to require them. … Read more

Bootstrap – Uncaught TypeError: Cannot read property ‘fn’ of undefined

You need to load jquery first before bootstrap. require.config({ paths: { jquery: ‘libs/jquery/jquery’, underscore: ‘libs/underscore/underscore’, backbone: ‘libs/backbone/backbone’, bootstrap: ‘libs/bootstrap’, jquerytablesorter: ‘libs/tablesorter/jquery.tablesorter’, tablesorter: ‘libs/tablesorter/tables’, ajaxupload: ‘libs/ajax-upload’, templates: ‘../templates’ }, shim: { ‘backbone’: { deps: [‘underscore’, ‘jquery’], exports: ‘Backbone’ }, ‘jquery’: { exports: ‘$’ }, ‘bootstrap’: { deps: [‘jquery’], exports: ‘$’ }, ‘jquerytablesorter’: { deps: [‘jquery’], exports: … Read more

Reduce array to a single string

A flurry of answers just came in and here is one more! The first option is using the native js join method which eliminates the need for reduce. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join var authors = [‘some author’, ‘another author’, ‘last author’]; var authorString = authors.join(“,”); console.log(authorString); IMPORTANT – if you’re array contains objects, then you might want to … Read more

How to ‘continue’ inside a each loop : underscore, node.js

_.each(users, function(u, index) { if (u.superUser === false) { return; //this does not break. _.each will always run //the iterator function for the entire array //return value from the iterator is ignored } //Some code }); Side note that with lodash (not underscore) _.forEach if you DO want to end the “loop” early you can … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)