---
title: "JS 判断数组中是否存在某字符串"
author: "可怜的猫"
date: "2016-02-01T15:07:52Z"
tags: ["js 数组"]
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2016-02-01T15:07:52Z"
id: 2275272
url: "https://lafecat.iteye.com/blog/2275272"
---

//判断数组中是否存在某字符串  
Array.prototype.S=String.fromCharCode(2);  
Array.prototype.in\_array=function(e){  
    var r=new RegExp(this.S+e+this.S);  
    return (r.test(this.S+this.join(this.S)+this.S));  
};

 

用法：

    var arr = \['a','b','c'];

    arr.in\_array("a");//返回值为true或false。存在为true,不存在为false。