Posts

Showing posts with the label lodash

How to use lodash to remove keys from a JSON object?

Image
Clash Royale CLAN TAG #URR8PPP How to use lodash to remove keys from a JSON object? I've been trying to transform some data using lodash without success. I am really new to javascript and lodash. How can I get the expected result? I've used mapValues and chain , but I didn't achieve anything good. mapValues chain const data = { "north": [ { "2018-07-01": { "date": "2018-07-01", "name": "david", "age": 11 }, "2018-07-02": { "date": "2018-07-02", "name": "damo", "age": 16 }, "2018-07-03": { "date": "2018-07-03", "name": "dani", "age": 12 } } ], "south": [ { "2018-07-01": [ { "fruit": "banana", ...

Importing lodash into angular2 + typescript application

Image
Clash Royale CLAN TAG #URR8PPP Importing lodash into angular2 + typescript application I am having a hard time trying to get the lodash modules imported. I've setup my project using npm+gulp, and keep hitting the same wall. I've tried the regular lodash, but also lodash-es. The lodash npm package: (has an index.js file in the package root folder) import * as _ from 'lodash'; Results in: error TS2307: Cannot find module 'lodash'. The lodash-es npm package: (has a defaut export in lodash.js i the package root folder) import * as _ from 'lodash-es/lodash'; Results in: error TS2307: Cannot find module 'lodash-es'. Both the gulp task and webstorm report the same issue. Funny fact, this returns no error: import 'lodash-es/lodash'; ... but of course there is no "_" ... My tsconfig.json file: { "compilerOptions": { "target": "es5", "module": "system", "moduleRe...

Lodash property iteratee on array of array

Lodash property iteratee on array of array Let's imagine I have the following JSON object: [ { "name": "productA", "prices": [ { "currency": "USD", "price": 10.0 }, { "currency": "EUR", "price": 9.0 } ] }, { "name": "productB", "prices": [ { "currency": "GBP", "price": 18.0 }, { "currency": "EUR", "price": 20.0 } ] }, ... ] I'd like to use Lodash to check if there's any object having the price with "GBP" currency, so I wrote the following: _.some(products, ['prices.currency', 'GBP']) H...