JSValue value = ...; // some JSValue if (value.isInt32()) { int integer = value.asInt32(); // safely cast to integer // do something with integer... }
JSValue array = ...; // some JSValue array if (array.isArray()) { for (size_t i = 0; i < array.size(); i++) { if (!array[i].isInt32()) { std::cout << "Array contains non-integer value" << std::endl; break; } } }In this example, the code checks whether the given JSValue represents an array using the isArray() function. If the value is indeed an array, the code then loops through each element of the array and checks if it is an integer using the isInt32() function. If a non-integer value is found, the code outputs a message and breaks out of the loop. Package library: This code example appears to use the V8 JavaScript engine library, which includes the JSValue class with the isInt32() function.