search

Home  >  Q&A  >  body text

javascript - How to elegantly get the key value of a cookie by key name?

Is it the only way to match the cookie key value corresponding to the specified key name using traditional regular expressions?

巴扎黑巴扎黑2753 days ago569

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-05-16 13:25:38

    There’s no way, that’s how cookies are stored, piled together, and you can only retrieve them in this way. Regular expression is already a very elegant way.
    If you want elegant key-value pairs, use localStorage/localSession

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-16 13:25:38

    You can only use regular string operations

    reply
    0
  • PHPz

    PHPz2017-05-16 13:25:38

    In fact, the simplest way is to use the cookie.js library to implement the operation. It is paired with jquery.cookie.js, and its API can be viewed. If you want to write native code, you can define your own functions to solve the problem.

    reply
    0
  • Cancelreply