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 1:
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
.