ecmascript-6

Convert camel case to sentence case in javascript

寵の児 提交于 2021-02-11 12:18:57
问题 I found myself needing to do camel case to sentence case string conversion with sane acronym support, a google search for ideas led me to the following SO post: Convert camelCaseText to Sentence Case Text Which is actually asking about title case not sentence case so I came up with the following solution which maybe others will find helpful or can offer improvements to, it is using ES6 which is acceptable for me and can easily be polyfilled if there's some horrible IE requirement. 回答1: The

Get array from nested json value objects

半城伤御伤魂 提交于 2021-02-11 12:15:15
问题 I've been searching an answer for that but didn't found it. I have an array like: const data2 = [{ "abc":{ companyCity:"Cupertino", conpanyName:"Apple" } }, { "def":{ companyCity:"Mountain View", conpanyName:"Google" } } ] And I'd like to convert to and array like omiting the parent keys: const data3 = [ { companyCity:"Cupertino", companyName:"Apple", }, { companyCity:"Mountain View", companyName:"Google" } ] Perhaps, libraries like lodash have a method to achieve that, but didn't find it.

How to group and sort object array?

丶灬走出姿态 提交于 2021-02-11 12:15:08
问题 I've got an object array which I have to group and sort: [ { id: 123, group: 'abc', metadata: { name: 'tom' }, date: ISODate("2019-07-08T20:33:40.475Z") }, { id: 456, group: 'def', metadata: { name: 'bob' }, date: ISODate("2019-07-08T20:33:40.475Z") }, { id: 789, group: 'def', metadata: { name: 'bob' }, date: ISODate("2019-07-10T20:33:40.475Z") }, { id: 234, group: 'ghi', metadata: { name: 'frank' }, date: ISODate("2019-07-10T20:33:40.475Z") }, { id: 567, group: 'abc', metadata: { name: 'tom'

Javascript array destructuring assignment gives strange errors [duplicate]

若如初见. 提交于 2021-02-11 09:55:43
问题 This question already has answers here : What are the rules for JavaScript's automatic semicolon insertion (ASI)? (6 answers) Closed 1 year ago . I've just noticed a strange error when using Javascript destructuring assignment, which took me some guesswork to resolve. I'm posting here so I can show what I learned. (I accept that the question about Javascript semicolon insertion is answered by What are the rules for JavaScript's automatic semicolon insertion (ASI)?, but my problem was about

Javascript array destructuring assignment gives strange errors [duplicate]

孤人 提交于 2021-02-11 09:54:12
问题 This question already has answers here : What are the rules for JavaScript's automatic semicolon insertion (ASI)? (6 answers) Closed 1 year ago . I've just noticed a strange error when using Javascript destructuring assignment, which took me some guesswork to resolve. I'm posting here so I can show what I learned. (I accept that the question about Javascript semicolon insertion is answered by What are the rules for JavaScript's automatic semicolon insertion (ASI)?, but my problem was about

Displaying date to month dd, yyyy

折月煮酒 提交于 2021-02-11 08:31:26
问题 given time_cancel = 2019-01-06T23:29:35.000Z, would like to format it to month dd, yyyy (in this example, it is January 06, 2019) In the following code, I have to write 12 if else block to convert mm to month i.e. in this case, is to convert 01 to January. is there a better /faster way to convert time_cancel to format month dd, yyyy in Javascript or Typescript/es6/react. Thanks in advance! let date = time_cancel.split("T")[0]; var dateArray = date.split("-"); var month; // 12 if else code if

Displaying date to month dd, yyyy

余生颓废 提交于 2021-02-11 08:31:01
问题 given time_cancel = 2019-01-06T23:29:35.000Z, would like to format it to month dd, yyyy (in this example, it is January 06, 2019) In the following code, I have to write 12 if else block to convert mm to month i.e. in this case, is to convert 01 to January. is there a better /faster way to convert time_cancel to format month dd, yyyy in Javascript or Typescript/es6/react. Thanks in advance! let date = time_cancel.split("T")[0]; var dateArray = date.split("-"); var month; // 12 if else code if

Does JS Set.has() method do shallow checks?

与世无争的帅哥 提交于 2021-02-11 06:36:30
问题 If I have a set of objects, like const s = new Set(); s.add({a: 1, b: 2}); s.add({a: 2, b: 2}); and I will do s.has({a: 1, b: 2}); Will I have a positive result? How does Set handle reference types? Is there a way to tell it to use custom checker/predicate? 回答1: It's expected that any native JavaScript API compare objects by their references and not their contents (including shallow comparison): ({a: 1, b: 2}) !== ({a: 1, b: 2}) Set isn't an exclusion, it does === comparison for every value

React images load locally but not on AWS Amplify

白昼怎懂夜的黑 提交于 2021-02-11 06:18:30
问题 Hi I am working with an API that retrieves the URL of an image. I am then trying to pass that URL into an tag as follows: <img class="img-fluid" src={this.state.representatives[i].pic}/> Locally I am met with But when I try to use the app on AWS Amplify, I am met with: I have tried hardcoding the URL into the app but it returns the same error. I am really confused where to go from here. For example the image URL pulled from the API for Mark Warner is http://bioguide.congress.gov/bioguide

React images load locally but not on AWS Amplify

二次信任 提交于 2021-02-11 06:18:27
问题 Hi I am working with an API that retrieves the URL of an image. I am then trying to pass that URL into an tag as follows: <img class="img-fluid" src={this.state.representatives[i].pic}/> Locally I am met with But when I try to use the app on AWS Amplify, I am met with: I have tried hardcoding the URL into the app but it returns the same error. I am really confused where to go from here. For example the image URL pulled from the API for Mark Warner is http://bioguide.congress.gov/bioguide