parseNumericObj
parseNumericObj(obj)
parseNumericObj(obj)
Converts numeric string values in an object to numbers, preserving non-numeric values.
Description
The parseNumericObj
function iterates through the input object and converts numeric string values to numbers while preserving non-numeric values. It creates a new object with the converted numeric values and the original non-numeric values.
Arguments
obj
(Record<string, any>
): The input object to parse numeric values from.
Returns
Record<string, any>
: A new object with numeric string values converted to numbers.
Example
Usage
Notes
The
parseNumericObj
function selectively converts numeric string values in an object to numbers while preserving non-numeric values.It ensures that only valid numeric strings are converted, maintaining the integrity of non-numeric data.
This function is useful for scenarios where specific values need to be treated as numbers for calculations or comparisons while keeping other values unchanged.
Last updated
Was this helpful?