Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Lodash startsWith()

How is the last statement true? The string does not start with "b". Could someone explain the position of "1" and why it makes that statement true?

var _ = require('lodash');
var result = _.startsWith('abc', 'b');

console.log(result);

result = _.startsWith('abc', 'b', 1);
console.log(result);
>node tester.js

false

true

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

As the documentation says the third parameter indicates the position to search from. So if you begin at index 1 then the string abc actually starts with b and thus it will return true.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading