Elisp: Check Element Exist in List

By Xah Lee. Date: . Last updated: .

Check Element Exist in List

member
(member x list)

Check if x is in list. If so, return a list starting with the first occurrence. Else return nil.

Comparison done using equal. 〔see Elisp: Equality Test

(member "4" '("3" "4" "5")) ;; ("4" "5")

Check Element Exist in List, for Symbols or Int

memq
(memq x list)

similar to member, but comparison done using eq.

Use this if all items are Symbols or int.

〔see Elisp: Equality Test

Check Element Exist in List, for Decimal Numbers

memql
(memql x list)

similar to member, but comparison done using eql.

good for if elements are decimal numbers.

〔see Elisp: Equality Test

Check Element Exist in List, for Strings

member-ignore-case
(member-ignore-case x list)

similar to member, except that x should be a string, and comparison ignores letter-case.

(member-ignore-case "A" '("b" "a")) ; ("a")

Reference

Emacs Lisp, Check Element Exist

Emacs Lisp, list

Special Lists

List Structure