You can achieve this by using conditional statements to check the length of the array. If the length is one, then you can return the object inside the array. If the length is greater than one, you can return the array itself.
Here's an example code block:
index.tsx488 chars15 lines
In the above code block, the getObjectOrArray
function takes an array as an argument. It then checks if the length of the array is equal to one using the if
statement. If it is, then it returns the object inside the array. Otherwise, it returns the array itself using the else
statement.
Hope this helps!
gistlibby LogSnag