How to use the isFinite function from lodash

Find comprehensive JavaScript lodash.isFinite code examples handpicked from public code repositorys.

lodash.isFinite is a function that checks whether a value is a finite number.

3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
* @category Objects
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if the `value` is finite, else `false`.
* @example
*
* _.isFinite(-101);
* // => true
*
* _.isFinite('10');
* // => true
fork icon73
star icon711
watch icon29

+ 9 other calls in file

189
190
191
192
193
194
195
196
197
198
module.exports.isEmpty             = _.isEmpty;
module.exports.isEqual             = _.isEqual;
module.exports.isEqualWith         = _.isEqualWith;
module.exports.isError             = _.isError;
module.exports.isEven              = _.isEven;
module.exports.isFinite            = _.isFinite;
module.exports.isFloat             = _.isFloat;
module.exports.isFunction          = _.isFunction;
module.exports.isIncreasing        = _.isIncreasing;
module.exports.isIndexed           = _.isIndexed;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

How does lodash.isFinite work?

lodash.isFinite is a method in the Lodash library which checks whether a value is a finite number, that is, not NaN, positive Infinity, or negative Infinity. It returns a boolean value of true if the value is a finite number, and false otherwise.

3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
// A seq is something considered a sequential composite type (i.e. arrays and `arguments`).
isSequential: function(x) { return (_.isArray(x)) || (_.isArguments(x)); },

// These do what you think that they do
isZero: function(x) { return 0 === x; },
isEven: function(x) { return _.isFinite(x) && (x & 1) === 0; },
isOdd: function(x) { return _.isFinite(x) && !_.isEven(x); },
isPositive: function(x) { return x > 0; },
isNegative: function(x) { return x < 0; },
isValidDate: function(x) { return _.isDate(x) && !_.isNaN(x.getTime()); },
fork icon3
star icon2
watch icon1

+ 412 other calls in file

428
429
430
431
432
433
434
435
436
437
438
439
440
console.log(isEqualWith); // => true


const isError = _.isError(new Error);
console.log(isError); // => true


const isFinite = _.isFinite(1);
console.log(isFinite); // => true


const isFunction = _.isFunction(() => {});
console.log(isFunction); // => true
fork icon0
star icon4
watch icon0

+ 15 other calls in file

Ai Example

1
2
3
4
5
const _ = require("lodash");

console.log(_.isFinite(42)); // Output: true
console.log(_.isFinite(-Infinity)); // Output: false
console.log(_.isFinite("42")); // Output: false

In this example, lodash.isFinite is used to determine if a given value is a finite number. The function returns true if the value is a number and is not equal to positive or negative infinity, and false otherwise. In the example, _.isFinite(42) returns true, _.isFinite(-Infinity) returns false, and _.isFinite('42') returns false.

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)