直接上代码: var str="adbbckddwerivka"; var arr=str.split(""); console.log(arr); //indexOf方法 var arr1=[]; for(var i=0;i<arr.length;i++){ if(arr1.indexOf(arr[i])<0){ arr1.push(arr[i]) } } console.log(arr1); //对象的方式 var arr2=[]; var obj1…
做前端的,一般实现功能是主要的,但是重中之重却是在做到功能完善的情况下提高性能. 1.遍历数组法 实现的思路:构建一个新的数组存放结果,for循环中每次从原数组中取出一个元素,用这个元素循环与结果数组对比,若结果数组中没有该元素,则存到结果数组中 <script> Array.prototype.unique1 = function(){ var res = [this[0]]; for(var i = 1; i < this.length; i++){ var repeat = fal…
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 200, 200)]; textField.backgroundColor=[UIColor redColor];…
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 200, 200)]; textField.backgroundColor=[UIColor redColor];…