Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Get first element from array or null using Ramda

I have an array

const arr1 = ["string1", "string2"]
const arr2 = []

And I want to get the first element of this array, or null if it is empty.

How can I do this using Ramda?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use R.propOr() to get a value from an object or array by key/index, and return a default if the result is undefined:

const firstOrNull = R.propOr(null, 0)

const arr1 = ["string1", "string2"]
const arr2 = []

console.log(firstOrNull(arr1))
console.log(firstOrNull(arr2))
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js" integrity="sha512-rZHvUXcc1zWKsxm7rJ8lVQuIr1oOmm7cShlvpV0gWf0RvbcJN6x96al/Rp2L2BI4a4ZkT2/YfVe/8YvB2UHzQw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!